package com.jason.campusinn.view;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.yuandian.wanna.R;
import com.yuandian.wanna.adapter.beautyClothing.DesginColorAdapter;
import com.yuandian.wanna.utils.CommonMethodUtils;
import com.yuandian.wanna.utils.LogUtil;

/** 添加名牌
 * Created by yuandian on 2015/5/8.
 */
public class DesignFamousBrandDialog extends Dialog implements View.OnClickListener {
    private Context mCotnext;
    @ViewInject(R.id.dialog_design_famous_brand_iv_close)
    private ImageView mIvClose;
    @ViewInject(R.id.dialog_design_famous_brand_btn_enter)
    private Button mBtnEnter;
    @ViewInject(R.id.design_famous_brand_edit_text)
    private EditText mEtBrand;
    @ViewInject(R.id.design_famous_brand_choose_color_gridview)
    private GridView mGridColor;
    @ViewInject(R.id.design_famous_brand_radiogroup_font)
    private RadioGroup mRaidoFont;
    @ViewInject(R.id.desing_famous_brand_radio_font_book_man)
    private RadioButton mRadioBookMan;
    @ViewInject(R.id.desing_famous_brand_radio_font_perpetua)
    private RadioButton mRadioPerpetua;
    @ViewInject(R.id.desing_famous_brand_radio_font_helvetica)
    private RadioButton mRadioHelvetica;

    private DesginColorAdapter mAdapter;
    private DesignCallBack callBack;
    private String tagFontID="";//4771 默认值
    private String tagColorID="";//6000
    private int mFrom;//区分美物、造物、奋斗者

    public DesignFamousBrandDialog(Context mCotnext){
        super(mCotnext, R.style.dialog_style);
        this.mCotnext = mCotnext;
        initViews();
        initContent();
    }

    public void setFrom(int mFrom) {
        this.mFrom = mFrom;
    }

    private void initViews() {
        setOwnerActivity((Activity) mCotnext);
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.BOTTOM);
        dialogWindow.setWindowAnimations(R.style.dialogMenu);
        dialogWindow.setAttributes(lp);
        LayoutInflater inflater = LayoutInflater.from(mCotnext);
        View view = inflater.inflate(R.layout.dialog_design_famous_brand, null);
        setContentView(view);
        setCanceledOnTouchOutside(true);
        ViewUtils.inject(this, view);

        mIvClose=(ImageView)view.findViewById(R.id.dialog_design_famous_brand_iv_close);
        mIvClose.setOnClickListener(this);

        mBtnEnter.setOnClickListener(this);
        mEtBrand.clearFocus();

        mAdapter = new DesginColorAdapter(mCotnext) {
            @Override
            public void setColor(String colorID) {
                 tagColorID= colorID;
                LogUtil.d("tagColorID======"+tagColorID);
            }
        };
        mGridColor.setAdapter(mAdapter);

        mRaidoFont.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.desing_famous_brand_radio_font_book_man:
//                        tagFontID = "RC12";
                        tagFontID = "4773";
                        break;
                    case R.id.desing_famous_brand_radio_font_perpetua:
//                        tagFontID = "RC11";
                        tagFontID = "4772";
                        break;
                    case R.id.desing_famous_brand_radio_font_helvetica:
//                        tagFontID = "RC10";
                        tagFontID = "4771";
                        break;
                }
                LogUtil.d("tagFontID======" + tagFontID);
            }
        });
        mRaidoFont.clearCheck();
//        mRaidoFont.check(R.id.desing_famous_brand_radio_font_helvetica);
//        mRadioBookMan.setTypeface(WannaApp.mFontTypefaceLight);
//        mRadioPerpetua.setTypeface(WannaApp.mFontTypefaceMedium);
//        mRadioHelvetica.setTypeface(WannaApp.mFontTypefaceNormal);
    }

    private void initContent(){

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.dialog_design_famous_brand_iv_close:
                tagFontID="";//4771
                tagColorID="";//6000
                mEtBrand.setText("");
                mAdapter.setmLastSelectedPosition(0);
                mRaidoFont.check(R.id.desing_famous_brand_radio_font_helvetica);
                callBack.setDesignChanged("添加文字名牌",tagColorID,tagFontID,mEtBrand.getText().toString().trim(),"","",0);
                this.dismiss();
                break;
            case R.id.dialog_design_famous_brand_btn_enter:
                if (TextUtils.isEmpty(mEtBrand.getText().toString().trim())) {
                    Toast.makeText(mCotnext, "请输入名牌内容！", Toast.LENGTH_LONG).show();
                } else if (CommonMethodUtils.isEmpty(tagFontID)) {
                    Toast.makeText(mCotnext, "请选择字体！", Toast.LENGTH_LONG).show();
                } else if (CommonMethodUtils.isEmpty(tagColorID)) {
                    Toast.makeText(mCotnext, "请选择颜色！", Toast.LENGTH_LONG).show();
                } else {
                    callBack.setDesignChanged("已添加文字名牌", tagColorID, tagFontID, mEtBrand.getText().toString().trim(), "", "", 0);
                    this.dismiss();
                }
                break;
        }

    }

    public void setCallBack(DesignCallBack callBack){
        this.callBack = callBack;
    }

    public interface DesignCallBack{
        public abstract void setDesignChanged(String title, String colorID, String fontID, String content, String locationID, String constellationID, int type);
    }
}
